<?
	$_POST['add_date'] = date("Y-m-d H:i:s");
	$_POST['date'] = date("Y-m-d",strtotime($_POST['date']));

	if($type = 1){
		$_POST['type_detail'] = 'Group Tour (15+)';
	}

	if($type = 2){
		$_POST['type_detail'] = 'Water Part Ticket';
	}

	$dsfm_reservation->add_reservation($_POST);

	$dsfm_email->set_form("reservation");

	$dsfm_email->fill("firstname", $_POST['firstname']);
	$dsfm_email->fill("lastname", $_POST['lastname']);
	$dsfm_email->fill("tel", $_POST['tel']);
	$dsfm_email->fill("email", $_POST['email']);
	$dsfm_email->fill("detail", $_POST['detail']);
	$dsfm_email->fill("date", $_POST['date']);

	$number = $_POST['adult'] + $_POST['kids'] + $_POST['guest'] +$_POST['senior'];

	$dsfm_email->fill("number", $number);

	$price = $dsfm_reservation->get_all_price();

	$ticket = "";

	if($_POST['adult'] != 0) {
		$ticket .= "ผู้ใหญ่จำนวน ".$_POST['adult']." ใบ เป็นเงิน ".($_POST['adult'] * $price['adult'])."<br>";
	}

	if($_POST['kids'] != 0) {
		$ticket .= "เด็กจำนวน ".$_POST['adult']." ใบ เป็นเงิน ".($_POST['kids'] * $price['kids'])."<br>";
	}

	if($_POST['guest'] != 0) {
		$ticket .= "ผู้พิการจำนวน ".$_POST['adult']." ใบ เป็นเงิน ".($_POST['guest'] * $price['guest'])."<br>";
	}

	if($_POST['senior'] != 0) {
		$ticket .= "ผู้สูงอายุจำนวน ".$_POST['adult']." ใบ เป็นเงิน ".($_POST['senior'] * $price['senior'])."<br>";
	}

	$total = ($_POST['adult'] * $price['adult']) + ($_POST['kids'] * $price['kids']) + ($_POST['guest'] * $price['guest']) + ($_POST['senior'] * $price['senior']);

	$ticket .= "รวมราคา ".$total."บาท";

	$dsfm_email->fill("ticket", $ticket);

	$dsfm_email->send_to($_POST['email']);
	$dsfm_email->send();

	alert($e['reservation-success']);

	redirect("reservation.php");
?>